import sys
import xlwings as xw

def doSum(rows):
    return sum(rows.value)

def doAvg(rows):

    sumVals = sum(rows.value)
    countVals = len(rows.value)

    return sumVals / countVals

#filePath = r"C:\test\v2\Excel.xlsm"
filePath = sys.argv[1]
#params = 'A1:A5000|SUM,B1:B5000|AVG'
params = sys.argv[2]

wb = xw.Book(filePath)
sheet = wb.sheets['Sheet1']

# command example: 
#'A1:A5000|SUM' 
# from ['A1:A5000|SUM','B1:B5000|AVG']
for command in params.split(','):
	# commandParams example: 
	# 'A1:A5000|SUM' to ['A1:A5000','SUM']
    commandParams = command.split('|')
	
	# coordinates example: 'A1:A5000'
    coordinates = commandParams[0]
    rows = sheet.range(coordinates)
	
	# commandAction example: 'SUM'
    commandAction = commandParams[1]
	
    # if commandAction == 'SUM':
    #     # ### 2.3 - print
    #     print(doSum(rows))
    # elif commandAction == 'AVG':
    #     print(doAvg(rows))

    if commandAction == 'SUM':
        sheet.range('E1').value = doSum(rows)
    elif commandAction == 'AVG':
        sheet.range('E2').value = doAvg(rows)

wb.save()